﻿<cfsilent>
	<cfscript>

		event.setArg("pageTitle", "教学运行管理 - 补考安排 - 自动编排时间地点");

		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");

		examId = event.getArg("EXID");
		
		currentTab = event.getArg("TabID", "labArrange");
		
		passArgs = structNew();
		
		/* 加载考试任务 */
	
		sql = "SELECT b.course_name,
					  a.wid,
             		  a.task_prog
				FROM t_resittask a 
					 INNER JOIN t_course b ON b.cid = a.cid 
				WHERE a.task_exrstid = :examId ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
   		queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
		
		rs_examTask= queryObj.execute( sql=sql ).getResult();
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('examResitArrange')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">补考编排</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 config"></i>《<cfoutput>#rs_examTask.course_name#</cfoutput>》 - 自动编排
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labArrange">class="active"</cfif> id="labArrange" tabTarget="Arrange">考试安排</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Arrange" class="tabContent">
					
					<div class="noticeBlock">
						<h3>《<cfoutput>#rs_examTask.course_name#</cfoutput>》</h3>
						<p>
							<span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期补考.
							该门课程考试计划安排于 <em id="weekLable"><cfoutput>#rs_examTask.wid#</cfoutput></em> 周
						</p>
					</div>
										
					<cfif rs_examTask.task_prog eq "0">

						<div class="noticeBlock">
							<h3 id="progress">正在自动进行考试安排</h3>
							<div id="logger"></div>
							<hr/>
						</div>
						<div id="outer"></div>

						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--

							$(document).ready(function() {

								$.post(
										"<cfoutput>#buildURL('apiExamResitTaskAvailableTimes')#</cfoutput>", 
										{
											'exid' : '<cfoutput>#examId#</cfoutput>',
											'seed': (new Date()).getTime()
										}, 
										function(data) {
											
											//$("#out").html(data);
											result = $.parseJSON(data);
											
											if (result.success) {
												
												/**/
												var logger = $("<ul></ul>");
													
												for ( var e=0; e < result.Progress.length; e++ ) {
													$("<li></li>").html(result.Progress[e]).appendTo(logger);
												}

												$("#logger").html(logger);
												
												var tabler = $("<table></table>").addClass("UIEditable");
												var thead = $("<thead><tr><td width='20'></td><td>考场</td><td>容量</td><td>考试人数</td><td>座次编号</td></tr></thead>")
												var tbody = $("<tbody></tbody>");
													
												var i = 0;
												for ( var e=0; e < result.ClassRoom.length; e++ ) {
													i++;
													var tr = $("<tr></tr>").addClass("editRows");
													
													$("<td></td>").addClass("index").html(i).appendTo(tr);
													$("<td></td>").html(result.ClassRoom[e][0]).appendTo(tr);
													$("<td><span></span></td>").addClass("numeric").html(result.ClassRoom[e][1]).appendTo(tr);
													$("<td><span></span></td>").addClass("numeric").html(result.ClassRoom[e][2]).appendTo(tr);
													$("<td><span></span></td>").addClass("numeric").html(result.ClassRoom[e][3] + " - " + result.ClassRoom[e][4]).appendTo(tr);
														
													tr.appendTo(tbody);	
												}
													
												thead.appendTo(tabler);
												tbody.appendTo(tabler);
													
												$("#outer").html(tabler);
												
												/* 延迟3秒跳转 */
												$('body').oneTime('3s',function(){
													window.location = '<cfoutput>#buildURL('examResitArrange')#</cfoutput>';
												});
												
											}
											else {
												alert(result.reason);
											}
											
										});
							
							});
								
							// -->
							//]]>				
						</script>
					
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>



